<#--
/*
 * $Id: Action.java 502296 2007-02-01 17:33:39Z niallp $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
-->
<#if parameters.label?exists>
</fieldset>  
</#if>
</form>
<#if (parameters.validate?default(false) == true)>
<script type="text/javascript">
    function validateForm_${parameters.id}() {
        form = document.getElementById("${parameters.id}");
        var validated = true;
    <#list parameters.tagNames as tagName>
        <#list tag.getValidators("${tagName}") as validator>
        // field name: ${validator.fieldName}
        // validator name: ${validator.validatorType}
        if (form.elements['${validator.fieldName}']) {
            field = form.elements['${validator.fieldName}'];
            var msg = "${validator.getMessage(action)?js_string}";
            <#if validator.validatorType = "required">
            if (isEmpty(field, msg)) {
                validated = false;
            }
            <#elseif validator.validatorType = "requiredstring">
            if (isStringEmpty(field, msg)) {
                validated = false;
            }
            <#elseif validator.validatorType = "stringlength">
            if (!isStringInRange(field, msg, ${validator.minLength?string}, ${validator.maxLength?string}, <#if validator.trim>true<#else>false</#if>)) {
                validated = false;
            } 
            <#elseif validator.validatorType = "regex">
            if (!matchesRegEx(field, msg, "${validator.expression?js_string}")) {
                validated = false;
            }
            <#elseif validator.validatorType = "email">
            if (!isEmail(field, msg)) {
                validated = false;
            }
            <#elseif validator.validatorType = "url">
            if (!isUrl(field, msg)) { 
                validated = false;
            }
            <#elseif validator.validatorType = "int">
            var min = <#if validator.min?exists>${validator.min?string}<#else>null</#if>;
            var max = <#if validator.max?exists>${validator.max?string}<#else>null</#if>;
            if (!isIntInRange(field, msg, min, max)) {
                 validated = false;
            }
            <#elseif validator.validatorType = "double">
            var min = <#if validator.minInclusive?exists>${validator.minInclusive?string}<#else>null</#if>;
            var max = <#if validator.maxInclusive?exists>${validator.maxInclusive?string}<#else>null</#if>;
            var minEx = <#if validator.minExclusive?exists>${validator.minExclusive?string}<#else>null</#if>;
            var maxEx = <#if validator.maxExclusive?exists>${validator.maxExclusive?string}<#else>null</#if>;
            if (!isFloatInRange(field, msg, min, max) || !isFloatInRangeEx(field, msg, minEx, maxEx)) {
                validated = false;
            }
            </#if>
        }
        </#list>
    </#list>
        return validated;
    }
</script>
</#if>
